package www.qiyue.RedissonCache;


import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.redisson.api.RLock;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
public class RedissonCache {
    @Autowired
    private JdbcTemplate jdbcTemplate;
    private ObjectMapper mapper = new ObjectMapper();
    @Cacheable(value = {"redis"},key = "#id")
    @RequestMapping("redis")
    public String redisTest(String id) throws InterruptedException, JsonProcessingException {

            String rent_un="SELECT * from ais_contract LIMIT  10 ";
            List<Map<String, Object>> list = jdbcTemplate.queryForList(rent_un);
            String json = mapper.writeValueAsString(list);
            //System.out.println(json);
            System.out.println("true = 加锁成功"+Thread.currentThread().getId());


        return json;
    }

}
